/*
 * 文件名: KeyBoardView.java
 * 版    权：  Copyright PingAn Technology All Rights Reserved.
 * 描    述: [该类的简要描述]
 * 创建人: EX-XUJIAO001
 * 创建时间: 2012-2-6
 * 
 * 修改人：
 * 修改时间:
 * 修改内容：[修改内容]
 */
package app.widget.PASafeKeyBoard;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.os.Handler;
import android.os.SystemClock;
import android.view.Gravity;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import app.log.APPLog;
import app.utils.Tools;

import com.longevityassistant.activity.R;

/**
 * @author EX-XUJIAO001
 * @date 2012-2-6
 * @version [Android PABank C01, @2012-2-6]
 * @description
 */
public class KeyBoardView extends PopupWindow implements OnClickListener,
		OnTouchListener {
	private Button btn1;
	private Button btn2;
	private Button btn3;

	private Button btn4;
	private Button btn5;
	private Button btn6;

	private Button btn7;
	private Button btn8;
	private Button btn9;

	private Button btn0;
	private LinearLayout lineardel;
	private Button btnpoint;

	private ImageView exitKey;
	private OnKeyDownBtnListener onKeyDownBtnListener;
	private OnKeyExitBtnListener onKeyExitBtnListener;

	private Button linearBtn0;
	private Button linearBtnPoint;
	private LinearLayout linearLinearDel;
	private Button linearABC;

	private Button btnSure;
	private LinearLayout linearSpace;
	//private Button btnComma;

	private ImageView letterExitkey;
	private Button btnq;
	private Button btnw;
	private Button btne;
	private Button btnr;
	private Button btnt;
	private Button btny;
	private Button btnu;
	private Button btni;
	private Button btno;
	private Button btnp;

	private Button btna;
	private Button btns;
	private Button btnd;
	private Button btnf;
	private Button btng;
	private Button btnh;
	private Button btnj;
	private Button btnk;
	private Button btnl;

	private Button btnz;
	private Button btnx;
	private Button btnc;
	private Button btnv;
	private Button btnb;
	private Button btnn;
	private Button btnm;

	private Button btn123;

	private RelativeLayout linearShift;
	
	//private Button btnBottomLine;
	//private Button btnMiddleLine;

	private static final int LETTERKEYBOARD = 2;
	private static final int NUMBERKEYBOARD = 1;
	private int keyBoradType = -1;

	private int letterTag = 0;
	private Context context;
	private KeyView keyView;
	private EditText editText;

	private boolean isDelPress = false;
	private int linearDelWidth;
	private int linearDelHeight;
	private static final int DELETETIME = 150;
	private static final int SENDEVENT = 300;
	
	
	private int currentCharKeyBoardType = 1;
	
	private int clickTimes;
	private int charKeyBoardType = 1;
	private LinearLayout btnSwiChar;
	
	
	private Button btnReturn;
	private ImageView keyboardDot;
	private ImageView keyboardShift;
	private ImageView keyDown;
	private ImageView keyUp;
	
	private LinearLayout linearcharDel;
	private ImageView charExitkey;
	private Button btnLt;
	private Button btnGt;
	private Button leftBracketShift;
	private Button rightBracketShift;
	private Button leftBracket;
	private Button rightBracket;
	private Button backSlash;
	private Button backSlashShift;
	private Button sLeftBracket;
	private Button sRightBracket;
	private Button dol;
	private Button equals;
	private Button with;
	private Button remainder;
	private Button topSharp;
	private Button grave;
	
	private Button comma;
	private Button period;
	private Button slashShift;
	private Button exclamationMark;
	private Button semicolonShift;
	private Button semicolon;
	private Button at;
	private Button graveShift;
	private Button bottomLine;
	private Button middleLine;
	private Button quot;
	private Button apos;
	private Button slash;
	private Button pound;
	private Button star;
	private Button plus;
		
	private LinearLayout linearUp;
	private LinearLayout linearDown;

	/**
	 * 
	 * [构造简要说明]
	 * 
	 * @param contentView
	 * @param width
	 * @param height
	 */
	public KeyBoardView(View contentView, int width, int height,
			int keyBoardType, Context context) {
		super(contentView, width, height);
		this.keyBoradType = keyBoardType;
		this.context = context;
		init();
	}

	public EditText getEditText() {
		return editText;
	}

	public void setEditText(EditText editText) {
		this.editText = editText;
	}

	public int getKeyBoradType() {
		return keyBoradType;
	}

	public void setKeyBoradType(int keyBoradType) {
		this.keyBoradType = keyBoradType;
	}

	public void setBtnpoint(Button btnpoint) {
		this.btnpoint = btnpoint;
	}

	public Button getBtnpoint() {
		return btnpoint;
	}

	private List<View> btnViewList;
	
	private OnTouchListener keyTouchListener = new OnTouchListener() {
		private View preView;
		@Override
		public boolean onTouch(View v, MotionEvent event) {
			if (preView != null && event.getAction() == MotionEvent.ACTION_UP) {
				preView.setBackgroundResource(R.drawable.app_widget_keyboard_btn);
				KeyBoardView.this.onTouch(preView, event);
				preView = null;
				return false;
			}
			int[] location = new int[2];
			int gx = (int)event.getX();
			int gy = (int)event.getY();
			for (View view : btnViewList) {
				view.getLocationInWindow(location);
				int top = location[1];
				int buttom = top + view.getHeight();
				int left = location[0];
				int right = left + view.getWidth();
				if (gx > left && gy > top && gx < right && gy < buttom) {
					if (preView == null) {
						preView = view;
						preView.setBackgroundResource(R.drawable.app_widget_keyboard_btn_c);
					} else if (preView != view) {
						preView.setBackgroundResource(R.drawable.app_widget_keyboard_btn);
						preView = view;
						preView.setBackgroundResource(R.drawable.app_widget_keyboard_btn_c);
					}
					KeyBoardView.this.onTouch(view, event);
					break;
				}
			}
			return false;
		}
	};

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 初始化
	 */
	private void init() {
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.app_widget_key, null);
		int w = Tools.getActualSize(this.context, 66);
		int y = Tools.getActualSize(this.context, 66);
		keyView = new KeyView(view,w,y);
		btnViewList = new ArrayList<View>();
		ViewGroup group = (ViewGroup) getContentView();
		group.setOnTouchListener(keyTouchListener);
		btn1 = (Button) group.findViewById(R.id.btn1);
		btn2 = (Button) group.findViewById(R.id.btn2);
		btn3 = (Button) group.findViewById(R.id.btn3);
		btn4 = (Button) group.findViewById(R.id.btn4);
		btn5 = (Button) group.findViewById(R.id.btn5);
		btn6 = (Button) group.findViewById(R.id.btn6);
		btn7 = (Button) group.findViewById(R.id.btn7);
		btn8 = (Button) group.findViewById(R.id.btn8);
		btn9 = (Button) group.findViewById(R.id.btn9);
		btn0 = (Button) group.findViewById(R.id.btn0);
		btnpoint = (Button) group.findViewById(R.id.btnpoint);
		lineardel = (LinearLayout) group.findViewById(R.id.lineardel);
		exitKey = (ImageView) group.findViewById(R.id.exit_key);

		btn1.setOnClickListener(this);
		btn2.setOnClickListener(this);
		btn3.setOnClickListener(this);
		btn4.setOnClickListener(this);
		btn5.setOnClickListener(this);
		btn6.setOnClickListener(this);
		btn7.setOnClickListener(this);
		btn8.setOnClickListener(this);
		btn9.setOnClickListener(this);
		btn0.setOnClickListener(this);
		btnpoint.setOnClickListener(this);

		lineardel.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				
				onTouchEventDispatch(v,event);
				return false;
			}
		});
		lineardel.setOnClickListener(this);
		exitKey.setOnClickListener(this);

		if (keyBoradType != -1) {
			linearBtn0 = (Button) group.findViewById(R.id.linear_btn0);
			linearBtnPoint = (Button) group.findViewById(R.id.linear_btnpoint);
			//btnBottomLine = (Button) group.findViewById(R.id.btnbottomline);
			//btnMiddleLine = (Button) group.findViewById(R.id.btnmiddleline);
			linearLinearDel = (LinearLayout) group
					.findViewById(R.id.linear_lineardel);
			linearABC = (Button) group.findViewById(R.id.btnABC);
			linearBtn0.setOnClickListener(this);
			linearBtnPoint.setOnClickListener(this);
			linearLinearDel.setOnTouchListener(new OnTouchListener() {
				
				@Override
				public boolean onTouch(View v, MotionEvent event) {
					onTouchEventDispatch(v,event);
					return false;
				}
			});
			linearLinearDel.setOnClickListener(this);
			
			linearABC.setOnClickListener(this);
			
			//btnBottomLine.setOnClickListener(this);
			//btnMiddleLine.setOnClickListener(this);

			letterExitkey = (ImageView) group
					.findViewById(R.id.letter_exit_key);
			letterExitkey.setOnClickListener(this);
			btnq = (Button) group.findViewById(R.id.btnq);
			btnw = (Button) group.findViewById(R.id.btnw);
			btne = (Button) group.findViewById(R.id.btne);
			btnr = (Button) group.findViewById(R.id.btnr);
			btnt = (Button) group.findViewById(R.id.btnt);
			btny = (Button) group.findViewById(R.id.btny);
			btnu = (Button) group.findViewById(R.id.btnu);
			btni = (Button) group.findViewById(R.id.btni);
			btno = (Button) group.findViewById(R.id.btno);
			btnp = (Button) group.findViewById(R.id.btnp);

			btna = (Button) group.findViewById(R.id.btna);
			btns = (Button) group.findViewById(R.id.btns);
			btnd = (Button) group.findViewById(R.id.btnd);
			btnf = (Button) group.findViewById(R.id.btnf);
			btng = (Button) group.findViewById(R.id.btng);
			btnh = (Button) group.findViewById(R.id.btnh);
			btnj = (Button) group.findViewById(R.id.btnj);
			btnk = (Button) group.findViewById(R.id.btnk);
			btnl = (Button) group.findViewById(R.id.btnl);

			btnz = (Button) group.findViewById(R.id.btnz);
			btnx = (Button) group.findViewById(R.id.btnx);
			btnc = (Button) group.findViewById(R.id.btnc);
			btnv = (Button) group.findViewById(R.id.btnv);
			btnb = (Button) group.findViewById(R.id.btnb);
			btnn = (Button) group.findViewById(R.id.btnn);
			btnm = (Button) group.findViewById(R.id.btnm);

			linearShift = (RelativeLayout) group.findViewById(R.id.linearshift);
			linearShift.setOnClickListener(this);

			btn123 = (Button) group.findViewById(R.id.btn123);
			btn123.setOnClickListener(this);
			
			btnSwiChar = (LinearLayout)group.findViewById(R.id.linearSwiChar);
			btnSwiChar.setOnClickListener(this);
			
			btnSure = (Button) group.findViewById(R.id.btnsure);
			linearSpace = (LinearLayout) group.findViewById(R.id.linearspace);
			//btnComma = (Button) group.findViewById(R.id.btncomma);
			btnSure.setOnClickListener(this);
			linearSpace.setOnClickListener(this);
			//btnComma.setOnClickListener(this);
/*
			btnq.setOnTouchListener(this);
			btnw.setOnTouchListener(this);
			btne.setOnTouchListener(this);
			btnr.setOnTouchListener(this);
			btnt.setOnTouchListener(this);
			btny.setOnTouchListener(this);
			btnu.setOnTouchListener(this);
			btni.setOnTouchListener(this);
			btno.setOnTouchListener(this);
			btnp.setOnTouchListener(this);

			btna.setOnTouchListener(this);
			btns.setOnTouchListener(this);
			btnd.setOnTouchListener(this);
			btnf.setOnTouchListener(this);
			btng.setOnTouchListener(this);
			btnh.setOnTouchListener(this);
			btnj.setOnTouchListener(this);
			btnk.setOnTouchListener(this);
			btnl.setOnTouchListener(this);

			btnz.setOnTouchListener(this);
			btnx.setOnTouchListener(this);
			btnc.setOnTouchListener(this);
			btnv.setOnTouchListener(this);
			btnb.setOnTouchListener(this);
			btnn.setOnTouchListener(this);
			btnm.setOnTouchListener(this);
*/
			btnViewList.add(btnq);
			btnViewList.add(btnw);
			btnViewList.add(btne);
			btnViewList.add(btnr);
			btnViewList.add(btnt);
			btnViewList.add(btny);
			btnViewList.add(btnu);
			btnViewList.add(btni);
			btnViewList.add(btno);
			btnViewList.add(btnp);
			btnViewList.add(btna);
			btnViewList.add(btns);
			btnViewList.add(btnd);
			btnViewList.add(btnf);
			btnViewList.add(btng);
			btnViewList.add(btnh);
			btnViewList.add(btnj);
			btnViewList.add(btnk);
			btnViewList.add(btnl);
			btnViewList.add(btnz);
			btnViewList.add(btnx);
			btnViewList.add(btnc);
			btnViewList.add(btnv);
			btnViewList.add(btnb);
			btnViewList.add(btnn);
			btnViewList.add(btnm);
			
			charExitkey = (ImageView)group.findViewById(R.id.char_exit_key);
			charExitkey.setOnClickListener(this);
			linearUp = (LinearLayout)group.findViewById(R.id.linearUp);
			linearUp.setOnClickListener(this);
			linearDown = (LinearLayout)group.findViewById(R.id.linearDown);
			linearDown.setOnClickListener(this);
			btnReturn = (Button)group.findViewById(R.id.btnReturn);
			btnReturn.setOnClickListener(this);
			linearcharDel = (LinearLayout)group.findViewById(R.id.linearchardel);
			linearcharDel.setOnClickListener(this);
			linearcharDel.setOnTouchListener(new OnTouchListener() {
				
				@Override
				public boolean onTouch(View v, MotionEvent event) {
					onTouchEventDispatch(v,event);
					return false;
				}
			});
			
			btnLt = (Button)group.findViewById(R.id.lt);
			btnLt.setOnClickListener(this);
			btnGt = (Button)group.findViewById(R.id.gt);
			btnGt.setOnClickListener(this);
			
			leftBracket = (Button)group.findViewById(R.id.leftbracket);
			leftBracket.setOnClickListener(this);
			rightBracket = (Button)group.findViewById(R.id.rightbracket);
			rightBracket.setOnClickListener(this);
			leftBracketShift = (Button)group.findViewById(R.id.leftbracketshift);
			leftBracketShift.setOnClickListener(this);
			rightBracketShift = (Button)group.findViewById(R.id.rightbracketshift);
			rightBracketShift.setOnClickListener(this);
			backSlash = (Button)group.findViewById(R.id.backslash);
			backSlash.setOnClickListener(this);
			backSlashShift = (Button)group.findViewById(R.id.backslashshift);
			backSlashShift.setOnClickListener(this);
			
			
			 comma = (Button)group.findViewById(R.id.comma);
			 comma.setOnClickListener(this);
			 period = (Button)group.findViewById(R.id.period);
			 period.setOnClickListener(this);
			 slashShift = (Button)group.findViewById(R.id.slashshift);
			 slashShift.setOnClickListener(this);
			 exclamationMark = (Button)group.findViewById(R.id.exclamationmark);
			 exclamationMark.setOnClickListener(this);
			 semicolonShift = (Button)group.findViewById(R.id.semicolonshift);
			 semicolonShift.setOnClickListener(this);
			 semicolon = (Button)group.findViewById(R.id.semicolon);
			 semicolon.setOnClickListener(this);
			 at = (Button)group.findViewById(R.id.at);
			 at.setOnClickListener(this);
			 graveShift = (Button)group.findViewById(R.id.graveshift);
			 graveShift.setOnClickListener(this);
			 bottomLine = (Button)group.findViewById(R.id.bottomline);
			 bottomLine.setOnClickListener(this);
			 middleLine = (Button)group.findViewById(R.id.middleline);
			 middleLine.setOnClickListener(this);
			 quot = (Button)group.findViewById(R.id.quot);
			 quot.setOnClickListener(this);
			 apos = (Button)group.findViewById(R.id.apos);
			 apos.setOnClickListener(this);
			 slash = (Button)group.findViewById(R.id.slash);
			 slash.setOnClickListener(this);
			 pound = (Button)group.findViewById(R.id.pound);
			 pound.setOnClickListener(this);
			 star = (Button)group.findViewById(R.id.star);
			 star.setOnClickListener(this);
			 plus = (Button)group.findViewById(R.id.plus);
			 plus.setOnClickListener(this);
			 
			 
		    
			
			 sLeftBracket = (Button)group.findViewById(R.id.sleftbracket);
			 sLeftBracket.setOnClickListener(this);
			 sRightBracket = (Button)group.findViewById(R.id.srightbracket);
			 sRightBracket.setOnClickListener(this);
			 dol = (Button)group.findViewById(R.id.dol);
			 dol.setOnClickListener(this);
			 equals = (Button)group.findViewById(R.id.equals);
			 equals.setOnClickListener(this);
			 with = (Button)group.findViewById(R.id.with);
			 with.setOnClickListener(this);
			 remainder = (Button)group.findViewById(R.id.remainder);
			 remainder.setOnClickListener(this);
			 topSharp = (Button)group.findViewById(R.id.topsharp);
			 topSharp.setOnClickListener(this);
			 grave = (Button)group.findViewById(R.id.grave);
			 grave.setOnClickListener(this);
			 
			 keyboardDot = (ImageView)group.findViewById(R.id.keyboard_dot);
			 keyboardShift = (ImageView)group.findViewById(R.id.keyboard_shift);
			 keyDown = (ImageView)group.findViewById(R.id.key_down);
			 keyUp = (ImageView)group.findViewById(R.id.key_up);
			 if(currentCharKeyBoardType == 1) {
					keyUp.setBackgroundResource(R.drawable.app_widget_keyboard_up_unenable);
					linearUp.setEnabled(false);
					//keyDown.setBackgroundResource(R.drawable.keyboard_down);
				}
			 if(currentCharKeyBoardType == 2) {
					//keyUp.setBackgroundResource(R.drawable.keyboard_up);
					keyDown.setBackgroundResource(R.drawable.app_widget_keyboard_down_unenable);
					linearDown.setEnabled(false);
				}
			 
		}

	}
	
	private void onTouchEventDispatch(View v, MotionEvent event){
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			APPLog.i("zbkc", "action_down");
			isDelPress = true;
			new Thread(new DeleteTask()).start();
			linearDelWidth = v.getWidth();
			linearDelHeight = v.getHeight();
			APPLog.i("zbkc", "linearDelWidth:" + linearDelWidth
					+ "linearDelHeigt:" + linearDelHeight);
			break;
		case MotionEvent.ACTION_MOVE:
			APPLog.i("zbkc", "event.getx:" + event.getX()
					+ "event.getY:" + event.getY());
			if (event.getX() < 0 || event.getY() < 0
					|| event.getX() > linearDelWidth
					|| event.getY() > linearDelHeight) {
				isDelPress = false;
			}
			break;
		case MotionEvent.ACTION_UP:
			APPLog.i("zbkc", "action_up");
			isDelPress = false;
			break;
		default:
			break;
		}
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn1:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_1));
			}
			break;
		case R.id.btn2:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_2));
			}
			break;
		case R.id.btn3:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_3));
			}
			break;
		case R.id.btn4:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_4));
			}
			break;
		case R.id.btn5:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_5));
			}
			break;
		case R.id.btn6:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_6));
			}
			break;
		case R.id.btn7:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_7));
			}
			break;
		case R.id.btn8:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_8));
			}
			break;
		case R.id.btn9:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_9));
			}
			break;
		case R.id.btn0:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0));
			}
			break;
		case R.id.btnpoint:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PERIOD));
			}
			break;
		/*case R.id.lineardel:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
			}
			break;*/
		case R.id.char_exit_key:
		case R.id.exit_key:
			if (onKeyExitBtnListener != null) {
				onKeyExitBtnListener.onKeyExitBtn();
			}
			break;

		case R.id.letter_exit_key:
			if (onKeyExitBtnListener != null) {
				onKeyExitBtnListener.onKeyExitBtn();
			}
			break;
		case R.id.btn123:

			if (onSwitchKeyBoardListenter != null) {
				onSwitchKeyBoardListenter.onSwitchKeyBoard(1);
			}
			if (letterTag == 1) {
				keyboardShift.setBackgroundResource(R.drawable.app_widget_keyboard_shift_no);
				keyboardDot.setBackgroundResource(R.drawable.app_widget_keyboard_white_dot);
				updateLetterKeyBoard(letterTag);
				letterTag = 0;
				clickTimes = 0;
			}
			/*
			 * if(onKeyDownBtnListener!=null){ Log.i("zbkc", "action_up");
			 * onKeyDownBtnListener.onKeyDownBtn(new
			 * KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEYCODE_SHIFT_LEFT)); }
			 */
			break;
		/*case R.id.linear_lineardel:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
			}
			break;*/
		case R.id.linearSwiChar:
			if (onSwitchKeyBoardListenter != null) {
				onSwitchKeyBoardListenter.onSwitchKeyBoard(3);
			}
			if (letterTag == 1) {
				keyboardShift.setBackgroundResource(R.drawable.app_widget_keyboard_shift_no);
				keyboardDot.setBackgroundResource(R.drawable.app_widget_keyboard_white_dot);
				updateLetterKeyBoard(letterTag);
				letterTag = 0;
				clickTimes = 0;
			}
			break;
		case R.id.btnABC:
			if (onSwitchKeyBoardListenter != null) {
				onSwitchKeyBoardListenter.onSwitchKeyBoard(2);
			}
			if (letterTag == 1) {
				updateLetterKeyBoard(letterTag);
				letterTag = 0;
			}
			break;
		case R.id.linear_btn0:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0));
			}
			break;
		case R.id.linear_btnpoint:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PERIOD));
			}
			break;
		/*case R.id.btnbottomline:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MINUS));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT));
				
			}
			break;*/
		case R.id.btnsure:
			if (onKeySureBtnListener != null) {
				onKeySureBtnListener.onKeySureBtn();
			}
			break;
		/*case R.id.btncomma:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_COMMA));
			}
			break;*/
		/*case R.id.btnmiddleline:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_MINUS));
			}
			break;*/
		case R.id.linearspace:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SPACE));
			}
			break;
		/*case R.id.linearshift:
			PABankLog.i("zbkc", "letterTag:" + letterTag);

			if (onKeyDownBtnListener != null) {
				if (letterTag == 0) {
					updateLetterKeyBoard(letterTag);
					// onKeyDownBtnListener.onKeyDownBtn(new
					// KeyEvent(KeyEvent.FLAG_CANCELED,KeyEvent.KEYCODE_SHIFT_LEFT));
					// onKeyDownBtnListener.onKeyDownBtn(keyEvent);
					// keyEvent =
					// KeyEvent.changeAction(keyEvent,KeyEvent.ACTION_UP);
					letterTag = 1;
				} else if (letterTag == 1) {
					PABankLog.i("zbkc", "upupuptoyou");
					updateLetterKeyBoard(letterTag);
					// onKeyDownBtnListener.onKeyDownBtn(new
					// KeyEvent(KeyEvent.FLAG_CANCELED,KeyEvent.KEYCODE_SHIFT_LEFT));
					// onKeyDownBtnListener.onKeyDownBtn(keyEvent);
					// keyEvent =
					// KeyEvent.changeAction(keyEvent,KeyEvent.ACTION_DOWN);
					letterTag = 0;
				}
			}
			break;*/
		case R.id.linearshift:
			clickTimes++;
			if (onKeyDownBtnListener != null) {
				
				if(clickTimes == 1){
					if (letterTag == 0) {
						keyboardShift.setBackgroundResource(R.drawable.app_widget_keyboard_shift);
						updateLetterKeyBoard(letterTag);
						// onKeyDownBtnListener.onKeyDownBtn(new
						// KeyEvent(KeyEvent.FLAG_CANCELED,KeyEvent.KEYCODE_SHIFT_LEFT));
						// onKeyDownBtnListener.onKeyDownBtn(keyEvent);
						// keyEvent =
						// KeyEvent.changeAction(keyEvent,KeyEvent.ACTION_UP);
						letterTag = 1;
					} /*else if (letterTag == 1) {
						updateLetterKeyBoard(letterTag);
						// onKeyDownBtnListener.onKeyDownBtn(new
						// KeyEvent(KeyEvent.FLAG_CANCELED,KeyEvent.KEYCODE_SHIFT_LEFT));
						// onKeyDownBtnListener.onKeyDownBtn(keyEvent);
						// keyEvent =
						// KeyEvent.changeAction(keyEvent,KeyEvent.ACTION_DOWN);
						letterTag = 0;
					}*/
				}else if(clickTimes == 2){
					keyboardDot.setBackgroundResource(R.drawable.app_widget_keyboard_yellow_dot);
				}else if(clickTimes == 3) {
					keyboardShift.setBackgroundResource(R.drawable.app_widget_keyboard_shift_no);
					keyboardDot.setBackgroundResource(R.drawable.app_widget_keyboard_white_dot);
					clickTimes = 0;
					updateLetterKeyBoard(letterTag);
					// onKeyDownBtnListener.onKeyDownBtn(new
					// KeyEvent(KeyEvent.FLAG_CANCELED,KeyEvent.KEYCODE_SHIFT_LEFT));
					// onKeyDownBtnListener.onKeyDownBtn(keyEvent);
					// keyEvent =
					// KeyEvent.changeAction(keyEvent,KeyEvent.ACTION_DOWN);
					letterTag = 0;
				}
				
				
			}
			break;
			
		case R.id.linearUp:
			/*if(currentCharKeyBoardType == 1) {
				keyUp.setBackgroundResource(R.drawable.keyboard_up_unenable);
				keyDown.setBackgroundResource(R.drawable.keyboard_down);
			}*/
			if(onSwitchCharKeyBoardListener != null && currentCharKeyBoardType != 1) {
				onSwitchCharKeyBoardListener.onSwitchCharKeyBoard(1);
				currentCharKeyBoardType = 1;
				
				keyUp.setBackgroundResource(R.drawable.app_widget_keyboard_up_unenable);
				keyDown.setBackgroundResource(R.drawable.app_widget_keyboard_down);
				linearUp.setEnabled(false);
				linearDown.setEnabled(true);
			}
			break;
		case R.id.linearDown:
			/*if(currentCharKeyBoardType == 2) {
				keyUp.setBackgroundResource(R.drawable.app_widget_keyboardup);
				keyDown.setBackgroundResource(R.drawable.app_widget_keyboarddown_unenable);
			}*/
			if(onSwitchCharKeyBoardListener != null && currentCharKeyBoardType != 2) {
				onSwitchCharKeyBoardListener.onSwitchCharKeyBoard(2);
				currentCharKeyBoardType = 2;
				
				keyUp.setBackgroundResource(R.drawable.app_widget_keyboard_up);
				keyDown.setBackgroundResource(R.drawable.app_widget_keyboard_down_unenable);
				linearDown.setEnabled(false);
				linearUp.setEnabled(true);
			}
			break;
			
		case R.id.btnReturn:
			if (onSwitchKeyBoardListenter != null) {
				onSwitchKeyBoardListenter.onSwitchKeyBoard(2);
			}
			/*if (letterTag == 1) {
				updateLetterKeyBoard(letterTag);
				letterTag = 0;
				clickTimes = 0;
			}*/
			break;
			
		case R.id.lt:
			
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(SystemClock.uptimeMillis(), "<", KeyCharacterMap.BUILT_IN_KEYBOARD, 0));
			}
			break;
		case R.id.gt:
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(SystemClock.uptimeMillis(), ">", KeyCharacterMap.BUILT_IN_KEYBOARD, 0));
			}
			break;
			
		case R.id.leftbracket:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_LEFT_BRACKET));
			}
			break;
		case R.id.rightbracket:
			
			if (onKeyDownBtnListener != null) {
			
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_RIGHT_BRACKET));
			}
			break;
		case R.id.leftbracketshift:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_LEFT_BRACKET));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT));
			}
			break;
		case R.id.rightbracketshift:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_RIGHT_BRACKET));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT));
			}
			break;
			
		case R.id.backslash:
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACKSLASH));
			}
			break;
		case R.id.backslashshift:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACKSLASH));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT));
			}
			break;
		case R.id.sleftbracket:
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(SystemClock.uptimeMillis(), "(", KeyCharacterMap.BUILT_IN_KEYBOARD, 0));
			}
			break;
			
		case R.id.srightbracket:
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(SystemClock.uptimeMillis(), ")", KeyCharacterMap.BUILT_IN_KEYBOARD, 0));
			}
			break;
		case R.id.dol:
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(SystemClock.uptimeMillis(), "$", KeyCharacterMap.BUILT_IN_KEYBOARD, 0));
			}
			break;
		case R.id.equals:
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_EQUALS));
			}
			break;
			
		case R.id.with:
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(SystemClock.uptimeMillis(), "&", KeyCharacterMap.BUILT_IN_KEYBOARD, 0));
			}
			break;
		case R.id.remainder:
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(SystemClock.uptimeMillis(), "%", KeyCharacterMap.BUILT_IN_KEYBOARD, 0));
			}
			break;
		case R.id.topsharp:
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(SystemClock.uptimeMillis(), "^", KeyCharacterMap.BUILT_IN_KEYBOARD, 0));
			}
			break;
		case R.id.grave:
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_GRAVE));
			}
			break;
			
		
		case R.id.comma:
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_COMMA));
			}
			break;
		case R.id.period:
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PERIOD));
			}
			break;
		case R.id.slashshift:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SLASH));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT));
			}
			break;
		case R.id.exclamationmark:
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(SystemClock.uptimeMillis(), "!", KeyCharacterMap.BUILT_IN_KEYBOARD, 0));
			}
			break;
		case R.id.semicolonshift:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SEMICOLON));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT));
			}
			break;
		case R.id.semicolon:
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SEMICOLON));
			}
			break;
		case R.id.at:
			if (onKeyDownBtnListener != null) {
				
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_AT));
			}
			break;
		case R.id.graveshift:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_GRAVE));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT));
			}
			break;
		case R.id.bottomline:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MINUS));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT));
			}
			break;
		case R.id.middleline:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MINUS));
			}
			break;
		case R.id.quot:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_APOSTROPHE));
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT));
			}
			break;
		case R.id.apos:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_APOSTROPHE));
			}
			break;
		case R.id.slash:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SLASH));
			}
			break;
		case R.id.pound:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_POUND));
			}
			break;
		case R.id.star:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_STAR));
			}
			break;
		case R.id.plus:
			if (onKeyDownBtnListener != null) {
				onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
						KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_PLUS));
			}
			break;
		default:
			break;
		}
	}

	private void sendKeyEvent(int keyEvent, View view, MotionEvent event) {
		Button btn = (Button)view;
		if(event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE){
			int location[] = new int[2];
			view.getLocationOnScreen(location);
			TextView keyTextView =  keyView.getTextView();
			int x = Tools.getActualSize(this.context, 17);
			int y = Tools.getActualSize(this.context, 65);
			if (keyView.isShowing()) {
				if (keyTextView
						.getText().equals(btn.getText())) {
					return;
				}
				keyView.update(location[0]-x, location[1]-y, -1, -1);
			} else {
				keyView.showAtLocation((ViewGroup) editText.getRootView(), Gravity.TOP | Gravity.LEFT, location[0]-x,location[1]-y);
			}
			keyTextView.setText(btn.getText());

		} else if (event.getAction() == MotionEvent.ACTION_UP) {
			if (onKeyDownBtnListener != null) {
				if (letterTag == 1) {
					onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
							KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT));
					onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
							KeyEvent.ACTION_DOWN, keyEvent));
					onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
							KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT));
					//如果单击那么大写只是一次性的,点击完大写之后,界面变成小写界面,标志变量回复
					if(clickTimes == 1) {
						keyboardShift.setBackgroundResource(R.drawable.app_widget_keyboard_shift_no);
						updateLetterKeyBoard(letterTag);
						letterTag = 0;
						clickTimes = 0;
					} else if (clickTimes == 2){//如果是双击
						
						
					}
				} else if (letterTag == 0) {
					onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
							KeyEvent.ACTION_DOWN, keyEvent));
				}
			}
			if (keyView.isShowing()) {
				keyView.dismiss();
			}
		}
	}

	private void updateLetterKeyBoard(int letterTag) {
		if (letterTag == 0) {
			btnq.setText("Q");
			btnw.setText("W");
			btne.setText("E");
			btnr.setText("R");
			btnt.setText("T");
			btny.setText("Y");
			btnu.setText("U");
			btni.setText("I");
			btno.setText("O");
			btnp.setText("P");

			btna.setText("A");
			btns.setText("S");
			btnd.setText("D");
			btnf.setText("F");
			btng.setText("G");
			btnh.setText("H");
			btnj.setText("J");
			btnk.setText("K");
			btnl.setText("L");

			btnz.setText("Z");
			btnx.setText("X");
			btnc.setText("C");
			btnv.setText("V");
			btnb.setText("B");
			btnn.setText("N");
			btnm.setText("M");
		} else if (letterTag == 1) {
			btnq.setText("q");
			btnw.setText("w");
			btne.setText("e");
			btnr.setText("r");
			btnt.setText("t");
			btny.setText("y");
			btnu.setText("u");
			btni.setText("i");
			btno.setText("o");
			btnp.setText("p");

			btna.setText("a");
			btns.setText("s");
			btnd.setText("d");
			btnf.setText("f");
			btng.setText("g");
			btnh.setText("h");
			btnj.setText("j");
			btnk.setText("k");
			btnl.setText("l");

			btnz.setText("z");
			btnx.setText("x");
			btnc.setText("c");
			btnv.setText("v");
			btnb.setText("b");
			btnn.setText("n");
			btnm.setText("m");
		}
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] event按下监听器
	 * 
	 * @author EX-XUJIAO001
	 * @version [Android PABank C01, 2012-2-15]
	 */
	public interface OnKeyDownBtnListener {
		void onKeyDownBtn(KeyEvent event);
	}

	public void setOnKeyDownBtnListener(
			OnKeyDownBtnListener onKeyDownBtnListener) {
		this.onKeyDownBtnListener = onKeyDownBtnListener;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 退出键监听
	 * 
	 * @author EX-XUJIAO001
	 * @version [Android PABank C01, 2012-2-15]
	 */
	public interface OnKeyExitBtnListener {
		void onKeyExitBtn();
	}

	public void setOnKeyExitBtnListener(
			OnKeyExitBtnListener onKeyExitBtnListener) {
		this.onKeyExitBtnListener = onKeyExitBtnListener;
	}

	public interface OnSwitchKeyBoardListenter {
		void onSwitchKeyBoard(int keyBoardType);
	}

	private OnSwitchKeyBoardListenter onSwitchKeyBoardListenter;

	public void setOnSwitchKeyBoardListenter(
			OnSwitchKeyBoardListenter onSwitchKeyBoardListenter) {
		this.onSwitchKeyBoardListenter = onSwitchKeyBoardListenter;
	}

	public interface OnKeySureBtnListener {
		void onKeySureBtn();
	}

	private OnKeySureBtnListener onKeySureBtnListener;

	public void setOnKeySureBtnListener(
			OnKeySureBtnListener onKeySureBtnListener) {
		this.onKeySureBtnListener = onKeySureBtnListener;
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		switch (v.getId()) {
		case R.id.btnq:
			sendKeyEvent(KeyEvent.KEYCODE_Q, v, event);
			break;
		case R.id.btnw:
			sendKeyEvent(KeyEvent.KEYCODE_W, v, event);
			break;
		case R.id.btne:
			sendKeyEvent(KeyEvent.KEYCODE_E, v, event);
			break;
		case R.id.btnr:
			sendKeyEvent(KeyEvent.KEYCODE_R, v, event);
			break;
		case R.id.btnt:
			sendKeyEvent(KeyEvent.KEYCODE_T, v, event);
			break;
		case R.id.btny:
			sendKeyEvent(KeyEvent.KEYCODE_Y, v, event);
			break;
		case R.id.btnu:
			sendKeyEvent(KeyEvent.KEYCODE_U, v, event);
			break;
		case R.id.btni:
			sendKeyEvent(KeyEvent.KEYCODE_I, v, event);
			break;
		case R.id.btno:
			sendKeyEvent(KeyEvent.KEYCODE_O, v, event);
			break;
		case R.id.btnp:
			sendKeyEvent(KeyEvent.KEYCODE_P, v, event);
			break;

		case R.id.btna:
			sendKeyEvent(KeyEvent.KEYCODE_A, v, event);
			break;
		case R.id.btns:
			sendKeyEvent(KeyEvent.KEYCODE_S, v, event);
			break;
		case R.id.btnd:
			sendKeyEvent(KeyEvent.KEYCODE_D, v, event);
			break;
		case R.id.btnf:
			sendKeyEvent(KeyEvent.KEYCODE_F, v, event);
			break;
		case R.id.btng:
			sendKeyEvent(KeyEvent.KEYCODE_G, v, event);
			break;
		case R.id.btnh:
			sendKeyEvent(KeyEvent.KEYCODE_H, v, event);
			break;
		case R.id.btnj:
			sendKeyEvent(KeyEvent.KEYCODE_J, v, event);
			break;
		case R.id.btnk:
			sendKeyEvent(KeyEvent.KEYCODE_K, v, event);
			break;
		case R.id.btnl:
			sendKeyEvent(KeyEvent.KEYCODE_L, v, event);
			break;

		case R.id.btnz:
			sendKeyEvent(KeyEvent.KEYCODE_Z, v, event);
			break;
		case R.id.btnx:
			sendKeyEvent(KeyEvent.KEYCODE_X, v, event);
			break;
		case R.id.btnc:
			sendKeyEvent(KeyEvent.KEYCODE_C, v, event);
			break;
		case R.id.btnv:
			sendKeyEvent(KeyEvent.KEYCODE_V, v, event);
			break;
		case R.id.btnb:
			sendKeyEvent(KeyEvent.KEYCODE_B, v, event);
			break;
		case R.id.btnn:
			sendKeyEvent(KeyEvent.KEYCODE_N, v, event);
			break;
		case R.id.btnm:
			sendKeyEvent(KeyEvent.KEYCODE_M, v, event);
			break;

		default:
			break;
		}
		return false;
	}

	class DeleteTask implements Runnable {

		@Override
		public void run() {
			while (true) {
				APPLog.i("zbkc", "isPress:" + isDelPress);
				if (!isDelPress) {
					break;
				}
				handler.sendEmptyMessage(SENDEVENT);

				try {
					Thread.sleep(DELETETIME);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}

		}

	}

	private Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case SENDEVENT:
				if (onKeyDownBtnListener != null) {
					onKeyDownBtnListener.onKeyDownBtn(new KeyEvent(
							KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
				}
				break;
			default:
				break;
			}
		};
	};
	

	
	public interface OnSwitchCharKeyBoardListener{
		void onSwitchCharKeyBoard(int charKeyBoardType);
	}
	
	private OnSwitchCharKeyBoardListener onSwitchCharKeyBoardListener;
	public void setOnSwitchCharKeyBoardListener(
			OnSwitchCharKeyBoardListener onSwitchCharKeyBoardListener) {
		this.onSwitchCharKeyBoardListener = onSwitchCharKeyBoardListener;
	}

}
